<template>
	<view v-if="questionsSwitch == true">
		<view class="questions">
			<view class="header">
				<view class="title">问答</view>
				<view class="more" @click="goToMoreQuestions()">更多</view>
			</view>
			
			<view class="list" v-if="questions.total">
				<view class="item" v-for="(item,index) in questions.data" :key="index">
					<view class="question">
						<image class="tb" src="../../../static/images/questions.png" mode="widthFix"></image>
						<text class="content">
							{{item.question}}
						</text>
					</view>
					<view class="answer">{{item.answer}}</view>
				</view>
			</view>
			<view class="empty-list" v-else>
				<view class="tip" @click="goToMoreQuestions()">
					还没有提问哦~立即提问
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'Questions',
		props:{
			type: {
				type: String,
				default: ''
			},
			typeId: {
				type: Number,
				default: ''
			}
		},
		data() {
			return {
				questionsSwitch: true,
				questions: {},
			}
		},
		created() {
			this.getQuestions()
		},
		methods: {
			/**
			 * 获取课程问答列表2条
			 */
			getQuestions: function(){
				let that = this
				let params = this.urlParams
				let data = {}
					data.action = 'list'
					data.info_id = this.typeId
					data.info_type = this.type
					data.rows = 2
				//获取评价列表数据
				//#ifdef MP-WEIXIN
				url = 'entry/wxapp/questions'
				//#endif
				//#ifdef H5
				url = 'entry/site/questions'
				//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							//console.log(res.data.data)
							that.questions = res.data.data
						}else{
							that.questionsSwitch = false
						}
					}
				})
			},
			/**
			 * 路由至更多评价列表
			 * @param {Object} type
			 * @param {Object} type_id
			 */
			goToMoreQuestions: function(){
				let info_id = this.typeId
				let info_type = this.type
				let urlParams = 'info_id='+info_id+'&info_type='+info_type
				let url = '../questions/list?' + urlParams
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			},
		}
	}
</script>

<style lang="scss">
	
	
	.questions {
		background-color: #fff;
		padding: 10px;
		.header {
			display: flex;
			.title {
				flex: 1;
				font-size: 28rpx;
				font-weight: 600;
				color: #000;
				margin-bottom: 16rpx;
			}
			.more {
				width: 160rpx;
				font-size: 24rpx;
				text-align: right;
				color: #999;
			}
		}
		
		.list {
			.item {
				border-bottom: 2rpx solid #f2f2f2;
				padding: 0 0 10rpx 0;
				margin-bottom: 10rpx;

				.question {
					color: #666;
					margin-bottom: 10rpx;
					font-size: 28rpx;
					color: #333;
					
					.tb {
						display: inline-block;
						width: 32rpx;
						height: 32rpx;
						overflow: hidden;
						margin-right: 10rpx;
						margin-bottom: 6rpx;
						vertical-align: middle;
					}
					.content {
						font-size: 28rpx;
						color: #333;
						line-height: 48rpx;
					}
				}
				.answer {
					font-size: 24rpx;
					color: #999;
					.time {
						font-size: 24rpx;
						color: 24rpx;
						color: #999;
					}
				}
				&:last-child {
					margin-bottom: 0;
					border-bottom: 0;
					padding-bottom: 0;
				}
			}
		}
		.empty-list {
			.tip {
				text-align: center;
				color: #999;
				font-size: 28rpx;
				padding: 20rpx 0;
			}
		}
	}
</style>
